package com.hjxr.xmgl.web.controller;

import java.util.List;

import com.hjxr.framework.web.domain.AjaxResult;
import com.hjxr.sysadmin.uitl.poi.ExcelUtil;
import com.hjxr.sysadmin.web.page.TableDataInfo;
import com.hjxr.xmgl.web.domain.QuotaTableData;
import com.hjxr.xmgl.web.service.IQuotaTableDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hjxr.framework.aspectj.lang.annotation.Log;
import com.hjxr.framework.aspectj.lang.enums.BusinessType;


/**
 * 指标数据指标Controller
 *
 * @author hjxr
 * @date 2021-12-02
 */
@Api("指标数据指标管理")
@RestController
@RequestMapping("/xmgl/tableData")
public class QuotaTableDataController extends BaseController
{
    @Autowired
    private IQuotaTableDataService quotaTableDataService;

    /**
     * 查询指标数据指标列表
     */
    @ApiOperation("list")
    @PreAuthorize("@ss.hasPermi('system:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuotaTableData quotaTableData , @RequestParam(value = "catId", required = false) String catId)
    {
//        startPage();  selectQuotaTableDataList
        if(catId != null && !catId.equals("")){
            quotaTableData.setCategoryId(catId);
        }
        System.out.println("quotaTableData---------" + quotaTableData);
        List<QuotaTableData> list = quotaTableDataService.selectQuotaTableDataAndFunctionList(quotaTableData);
        return getDataTable(list);
    }

    /**
     * 导出指标数据指标列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:export')")
    @Log(title = "指标数据指标", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QuotaTableData quotaTableData)
    {
        List<QuotaTableData> list = quotaTableDataService.selectQuotaTableDataList(quotaTableData);
        ExcelUtil<QuotaTableData> util = new ExcelUtil<QuotaTableData>(QuotaTableData.class);
        return util.exportExcel(list, "data");
    }

    /**
     * 获取指标数据指标详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:data:query')")
    @GetMapping(value = "/{fieldId}")
    public AjaxResult getInfo(@PathVariable("fieldId") String fieldId)
    {
        return AjaxResult.success(quotaTableDataService.selectQuotaTableDataById(fieldId));
    }

    /**
     * 新增指标数据指标
     */
    @PreAuthorize("@ss.hasPermi('system:data:add')")
    @Log(title = "指标数据指标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuotaTableData quotaTableData)
    {
        return toAjax(quotaTableDataService.insertQuotaTableData(quotaTableData));
    }

    /**
     * 修改指标数据指标
     */
    @PreAuthorize("@ss.hasPermi('system:data:edit')")
    @Log(title = "指标数据指标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuotaTableData quotaTableData)
    {
        return toAjax(quotaTableDataService.updateQuotaTableData(quotaTableData));
    }

    /**
     * 删除指标数据指标
     */
    @PreAuthorize("@ss.hasPermi('system:data:remove')")
    @Log(title = "指标数据指标", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fieldIds}")
    public AjaxResult remove(@PathVariable String[] fieldIds)
    {
        return toAjax(quotaTableDataService.deleteQuotaTableDataByIds(fieldIds));
    }
}
